/************************公告管理js*********************************/
define(function(require, exports, module) {
	
	var $ = require("jquery1.7");
	var noticeBoardService = require("bean/noticeBoardService");
	var utils = require("utils");
	var ctx = utils.constants.ctx;
	var ui = require("ui");
	var BlackBox = require("blackbox");
	var blackBox = new BlackBox();
	
	//添加公告
	$("#addNOticeBtn").bind("click",function(){
		location.href = ctx + "/back/website/noticeContent";
	});
	
	//批量删除
	$("#deleteNoticeBtn").bind("click", function(){
		if ($('input[name=items]:checkbox:checked').length <= 0) {
			blackBox.alert("请选择公告");
			return;
		}
		blackBox.confirm("确定要删除公告？",function(isOk){
			if(isOk){
				var array = [];
				$('input[name=items]:checkbox:checked').each(function() {
					
					var id = $(this).attr("id").replace("notice_", "");
					array.push(id);   
				});
				if (array.length != 0) {
					try{
						ui.mask().show("请稍候...");
						noticeBoardService.deleteNoticeList(array);
						ui.mask().hide();
						blackBox.alert("删除成功");
						window.location.reload(true);
					} catch (e) {
						ui.mask().hide();
						blackBox.alert("删除失败:"+e.message);
					}
				}
			}
		},{
			title:'提示',
			value:'确认'
		})
	});
	
	//发布公告
	$("#issueNoticeBtn").bind("click",function(){
		if ($('input[name=items]:checkbox:checked').length != 1) {
			blackBox.alert("请选择一条公告");
			return;
		}
		blackBox.confirm("确定要发布？",function(isOk){
			if(isOk){
				var notice_id = $('input[name=items]:checkbox:checked').attr("id").replace("notice_", "");
				try{
					ui.mask().show("请稍候...");
					noticeBoardService.issueNotice(notice_id);
					ui.mask().hide();
					blackBox.alert("发布成功");
					window.location.reload(true);
				}catch (e) {
					ui.mask().hide();
					blackBox.alert("发布失败:"+e.message);
				}
			}
		},{
			title:'提示',
			value:'确认'
		})
	});
	
	
	//修改公告
	$(".updateNotice").bind("click",function(){
		var id = $(this).attr("data").replace("notice_", "");
		var notice=noticeBoardService.findNoticeById(id);
		if(notice.issueStatus!=0){
			blackBox.alert("已发布的公告不可修改");
			return;
		}
		location.href = ctx + "/back/website/noticeContent?noticeId="+id;
	});
	
	//公告置顶
	$(".noticeToTop").bind("click",function(){
		var id = $(this).attr("data").replace("notice_", "");
		noticeBoardService.noticeToTop(id);
		blackBox.alert("置顶成功！");
		window.location.reload();
	});
	
	//公告不置顶
	$(".noticeNoToTop").bind("click",function(){
		var id = $(this).attr("data").replace("notice_", "");
		noticeBoardService.noticeNoToTop(id);
		blackBox.alert("成功取消置顶");
		window.location.reload();
	});
	//查看公告详细信息
	$(".checkNoticeDetail").click(function(){
		var id = $(this).attr("data").replace("notice_", "");
		window.open("/back/website/checkNoticeDetail/"+id, "_blank");
	});
	
	//查询公告
	$("#notice_searchBtn").click(function(){
		var name=$("#notice_search_keyword").val();
		if(name==null){
			blackBox.alert("请输入公告标题");
			return;
		}
		location.href=ctx+"/back/website/noticeManager?name="+name;
	});
});

